/*
 * gy_enpclientfactory.h
 *
 *  Created on: 2015年9月15日
 *      Author: gaoyi
 */

#ifndef GY_ENPCLIENTFACTORY_H_
#define GY_ENPCLIENTFACTORY_H_

#include "gy_enpdef.h"
#include "gy_enpclient.h"
#include <map>
#include <list>
#include <set>


class GYEnpClientFactory
{
protected:
	unsigned int			m_uiClientSeq; /////< 客户端序号，每个客户端连接分配一个
	std::map<unsigned int, GYEnpClient>	m_stMgr;
	std::set<unsigned int>		m_stRemain; //remain set
public:
	GYEnpClientFactory():m_uiClientSeq(0)
	{
		m_stMgr.clear();
		m_stRemain.clear();
	}
	virtual ~GYEnpClientFactory()
	{

	}
public:
	unsigned int	GetClientSeq()
	{
		m_uiClientSeq++;
		return m_uiClientSeq;
	}
public:
	GYEnpClient* Alloc();
	int			Free(GYEnpClient* pstClient);
	int			Free(unsigned int seq);

	GYEnpClient* Find(unsigned int seq);
public:
	int SetEmpty(unsigned int seq);
	int SetRemain(unsigned int seq);
	bool IsRemain(unsigned int seq);
public:
	int	GetClientSize();
	int	GetRemainSize();
};



#endif /* GY_ENPCLIENTFACTORY_H_ */
